
@extends('admin.public.admin')

@section('main')
<!-- 内容 -->
<div class="mws-panel grid_8">

		<div class="mws-panel-header">
			<span><i class="icon-table"></i> 管理员列表</span>
		</div>

        <div class="mws-panel-body no-padding">
            	<div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">

               <form method="get" action="/admin/admin">

            		  <div id="DataTables_Table_1_length" class="dataTables_length">

              			<label>显示
  	                        <select size="1" name="count" aria-controls="DataTables_Table_1">
                      <option value="10" @if(!empty($request['count']) && $request['count'] == 10) selected @endif>10</option>
  				        		<option value="20" @if(!empty($request['count']) && $request['count'] == 20) selected @endif>20</option>
  				        		<option value="30" @if(!empty($request['count']) && $request['count'] == 30) selected @endif>30</option>
  				        		<option value="50" @if(!empty($request['count']) && $request['count'] == 50) selected @endif>50</option>
  	                        </select>
              			条
              			</label>
            		  </div>

            <div class="dataTables_filter" id="DataTables_Table_1_filter">
                    <label>
                    	搜索: <input type="text" name="search" value="{{$request['search'] or ''}}" aria-controls="DataTables_Table_1">
                            <input type="submit" class="btn btn-success btn-xs" value="搜索">
                    </label>
            </div>
            </form>
            <table class="mws-datatable-fn mws-table dataTable" id="DataTables_Table_1" aria-describedby="DataTables_Table_1_info">
                <thead>
                    <tr role="row">
		                    <th >ID</th>
		                    <th>用户名</th>
		                    <th>电话</th>
                        <th>邮箱</th>
		                    <th>最后登录</th>
		                    <th>权限</th>
		                    <th>状态</th>
		                    <th>操作</th>
                    </tr>
                </thead>
                <?php
                  $num=0;
                ?>
            <tbody role="alert" aria-live="polite" aria-relevant="all">
            @foreach($data as $k=>$v)

            		<tr>
                      <td class="">{{++$num}}</td>
	                    <td class="">{{$v['nickname']}}</td>
	                    <td class="">{{$v['tel']}}</td>
	                    <td class="">{{$v['email']}}</td>
                      <td>{{date('Y-m-d H:i:s',$v['lasttime'])}}</td>

              @if($v['authority'])
                      <td>
                          <span class="btn btn-danger" onclick="authority(this,{{$v['id']}},1)">超级管理员</span>
                      </td>
             @else
                      <td>
                          <span class="btn btn-success" onclick="authority(this,{{$v['id']}},0)">普通管理员</span>
                      </td>
             @endif
             <!-- 管理员状态 0 启用 1禁用 -->
              @if($v['statu'])
                      <td><span class="btn btn-danger" onclick="statu(this,{{$v['id']}},1)">禁用</span></td>
             @else
                      <td><span class="btn btn-success" onclick="statu(this,{{$v['id']}},0)">正常</span></td>
             @endif

                      <td align="center" width="100px">
                        	<a href="/admin/admin/{{$v['id']}}/edit"  class="icon-pencil-2" title="修改"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        	<a href="javascript:;" onclick="deletes(this,{{$v['id']}})"  class="icon-trash" title="删除"></a>
                        </td>
                    </tr>

              @endforeach
             </tbody>
           </table>

           <!-- 分页 -->
              <div id="page_page">
                   {!! $data->appends($request)->render()!!}
              </div>
           </div>
      </div>
</div>
<script>

  // ajax修改状态

  function statu(obj,id,statu){

    // 发送ajax请求

    if (statu) {
      // 发送ajax请求

      $.post('/admin/admin/ajaxStatu',{id:id,"_token":"{{csrf_token()}}","statu":"0"},function(data){

        if (data==1) {
          
          $(obj).parent().html('<span class="btn btn-success" onclick="statu(this,'+id+',0)">正常</span>');
        }

      });
    }else{

      $.post('/admin/admin/ajaxStatu',{id:id,"_token":"{{csrf_token()}}","statu":"1"},function(data){

        if (data==1) {
          $(obj).parent().html('<span class="btn btn-danger" onclick="statu(this,'+id+',1)">禁用</span>');
        }

      });
    }
  }


// ajax权限

  function authority(obj,id,authority){

    // 发送ajax请求

    if (authority) {
      // 发送ajax请求

      $.post('/admin/admin/ajaxAuthority',{id:id,"_token":"{{csrf_token()}}","authority":"0"},function(data){

        if (data==1) {
          $(obj).parent().html('<span class="btn btn-success" onclick="authority(this,'+id+',0)">普通管理员</span>');
        }

      });
    }else{

      $.post('/admin/admin/ajaxAuthority',{id:id,"_token":"{{csrf_token()}}","authority":"1"},function(data){

        if (data==1) {
          $(obj).parent().html('<span class="btn btn-danger" onclick="authority(this,'+id+',1)">超级管理员</span>');

        }

      });
    }
  }


  // ajax删除

  function deletes(obj,id){
    // 发送ajax请求

    $.post("/admin/admin/"+id,{"_token":'{{csrf_token()}}',"_method":"delete"},function(data){
      // 判断是否成功

      if (data==1) {
        // 移除数据
          alert("删除成功");
        window.location.href = "/admin/admin";
      }else{
        alert('删除失败');
      }
    })
  }

</script>
	@endsection